<template>
	<view class="page">
		<view class="form-content">
			<u-form :model="formData" ref="uForm" class="uForm" label-position="top">
				<u-form-item prop="type" label="企业服务类型" label-width="auto">
					<u-radio-group v-model="formData.type">
						<u-radio key="1" :name="1">顾问服务</u-radio>
						<u-radio key="2" :name="2">数字化服务</u-radio>
						<u-radio key="2" :name="3">管家服务</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item prop="customerName" label="企业名称" label-width="auto">
					<u-input v-model="formData.customerName" placeholder="请输入企业名称" />
				</u-form-item>
				<u-form-item prop="hideName" label="脱敏内容（设置企业名称关键字隐藏,需连续文字）" label-width="auto">
					<u-input v-model="formData.hideName" placeholder="请输入脱敏内容" />
				</u-form-item>
				<u-form-item prop="linkName" label="企业联系人" label-width="auto">
					<u-input v-model="formData.linkName" placeholder="请输入企业联系人" />
				</u-form-item>
				<u-form-item prop="mobilePhone" label="联系人手机号" label-width="auto">
					<u-input v-model="formData.mobilePhone" placeholder="请输入联系人手机号" maxlength="11" type="number" />
				</u-form-item>
				<u-form-item prop="socialCreditCode" label="统一社会信用代码" label-width="auto">
					<u-input v-model="formData.socialCreditCode" placeholder="请输入统一社会信用代码" />
				</u-form-item>
				<u-form-item prop="legalRepresentative" label="法定代表人" label-width="auto">
					<u-input v-model="formData.legalRepresentative" placeholder="请输入法定代表人" />
				</u-form-item>
				<u-form-item prop="establishmentDate" label="成立日期" label-width="auto">
					<dateTime v-model="formData.establishmentDate" :showLabel="false" :showArrow="false"
						:required="false" :disabled="true" className="new-date-picker" placeholder="请选择成立日期"
						jnpfKey="date"></dateTime>
				</u-form-item>
				<u-form-item prop="registeredCapital" label="注册资本" label-width="auto">
					<u-input v-model="formData.registeredCapital" placeholder="请输入注册资本" type="digit" />
					<view slot="right">万元</view>
				</u-form-item>
				<u-form-item prop="industryClassification" label="行业分类" label-width="auto">
					<u-input v-model="formData.industryClassification" placeholder="请输入行业分类" />
				</u-form-item>
				<u-form-item prop="actualBusinessPreArea" label="实际经营地址面积" label-width="auto">
					<u-input v-model="formData.actualBusinessPreArea" placeholder="请输入实际经营地址面积" type="digit" />
					<view slot="right">平米</view>
				</u-form-item>
				<u-form-item prop="customerProfile" label="附件信息" label-width="auto">
					<JNPFUpload v-model="attendanceFileList" :fileSize='2' :limit='10' :showLabel="false"
						@uploading="uploading">
					</JNPFUpload>
				</u-form-item>
			</u-form>
		</view>
		<view class="save-bottom">
			<view class="fixed-btn save-padding">
				<u-button type="primary" :disabled="btnDisabled" shape="circle" @click="onSubmit">确定</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import dateTime from '@/components/dateTime/dateTime.vue'
	const apiUrl = "/api/Jiushi/Customerbase";
	export default {
		components: {
			dateTime
		},
		name: 'customerBase',
		data() {
			return {
				formData: {
					id: null,
					businessId: this.$helper.getUuid(),
					type: 1,
					customerName: null,
					linkName: null,
					mobilePhone: null,
					socialCreditCode: null,
					establishmentDate: null,
					legalRepresentative: null,
					registeredCapital: null,
					registeredAddress: null,
					customerProfile: null,
					industryClassification: null,
					actualBusinessAddress: null,
					actualBusinessPreArea: null,
					actualControllerId: null,
					mainProducts: null,
					insuredEmployeeCount: 0,
					nonInsuredEmployeeCount: 0,
					partTimeEmployeeCount: 0,
					currentState: 0
				},
				rules: {
					hideName: [{
						required: true,
						message: '请输入脱敏字段',
						trigger: ['change', 'blur'],
					}],
					actualBusinessPreArea: [{
						required: true,
						message: '请输入实际经营面积',
						trigger: ['change', 'blur'],
					}],
				},
				dictionaryData: this.$jnpf.dictionaryData('Education'),
				attendanceFileList: [],
				btnDisabled: false
			}
		},
		onLoad(options) {
			if (options.id) {
				this.formData.id = options.id
				this.init()
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			uploading(flag) {
				this.btnDisabled = flag
			},
			input(list) {
				this.btnDisabled = true
				if (list.length > 0) {
					let count = list.filter(item => item.progress == 100)
					if (count = list.length) {
						this.btnDisabled = false
					}
				}
			},
			/* 初始化请求 */
			init() {
				this.$helper.ajax({
					url: apiUrl + "/" + this.formData.id,
					method: "GET",
					contentType: "application/json",
					success: res => {
						this.formData = res.data.data
						if (this.formData.customerProfile) {
							this.attendanceFileList = res.data.data.customerProfile.split(',').map(item => {
								let tempItem = {
									url: item
								}
								return tempItem
							})
						}
					}
				});
			},
			/* 表单提交 */
			onSubmit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.formData.customerProfile = this.attendanceFileList.map(item => {
							return item.url
						}).join(',')
						let url = apiUrl;
						let method = "POST";
						if (this.formData.id) {
							url = url + "/" + this.formData.id;
							method = "PUT";
						}
						this.$helper.ajax({
							url: url,
							method: method,
							contentType: "application/json",
							data: this.formData,
							success: res => {
								this.$helper.msg('保存成功', 'success');
								uni.setStorage({
									key: "refreshPage",
									data: true
								})
								uni.navigateBack();
							}
						});
					}
				})
			},
		}
	}
</script>

<style>

</style>